import App from './App'
import ElementUI from 'element-ui';
import uvUI from '@/uni_modules/uv-ui-tools'
import md5 from 'js-md5';
import {
	Request
} from '@/util/request/index'
import store from '@/store'
import vuexStore from "@/store/$uv.mixin.js"
import sys from "@/util/sys.js"
import { aes_encrypt, aes_decrypt,format_duration } from '@/util/aes_endecrypt.js';
// uni.$uv.setConfig({
// 	config: {
// 			// 修改默认单位为rpx，相当于执行 uni.$uv.config.unit = 'rpx'
// 			unit: 'px'
// 	},
// 	props: {
// 		text: {
// 			color: {
// 				default: 'red'
// 			}
// 		}
// 	}
// })
// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
Vue.use(uvUI, {
	mpShare: true
})
Vue.prototype.isPc = sys.isPc
Vue.prototype.screen = sys.screen
Vue.prototype.isApp = sys.isApp
Vue.prototype.aes_encrypt = aes_encrypt
Vue.prototype.aes_decrypt = aes_decrypt
Vue.prototype.format_duration = format_duration
Vue.prototype.$md5 = md5
// Vue.prototype.$uv = uni.$uv
Vue.use(ElementUI);
Vue.use(store)
Vue.mixin(vuexStore)
App.mpType = 'app'
try {
	function isPromise(obj) {
		return (!!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function");
	}
	// 统一 vue2 API Promise 化返回格式与 vue3 保持一致
	uni.addInterceptor({
		returnValue(res) {
			if (!isPromise(res)) {
				return res;
			}
			return new Promise((resolve, reject) => {
				res.then((res) => {
					if (res[0]) {
						reject(res[0]);
					} else {
						resolve(res[1]);
					}
				});
			});
		},
	});
} catch (error) {}
const app = new Vue({
	store,
	// ElementUI,
	...App
})
app.$mount()
// 引入请求封装
Request(app)
// #endif
// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	app.use(uvUI, {
		mpShare: true
	})
	app.config.globalProperties.isPc = sys.isPc
	app.config.globalProperties.screen = sys.screen
	app.config.globalProperties.isApp = sys.isApp
	app.use(store)
	app.mixin(vuexStore)
	// 引入请求封装
	Request(app)
	return {
		app
	}
}
// #endif